home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 371_01 / exampl5.c < prev    next >
Text File  |  1991-12-24  |  4KB  |  213 lines

  1. /***************************************************************************
  2. * EXAMPL4.C
  3. * A dumb screen editor
  4. * ****************************************************************************/
  5.  
  6. #include <Windows.h>
  7. #include <WinDosIO.h>
  8.  
  9.  
  10. long far pascal WndProc(HWND, WORD, WORD, LONG);
  11.  
  12. short currentHandle;
  13. HWND idWindow;
  14. HANDLE hInst;
  15. short isText;
  16. short saved;
  17.  
  18. #define F1    59
  19. #define F2    60
  20. #define F3    61
  21. #define F4    62
  22. #define F5    63
  23. #define F6    64
  24. #define F7    65
  25.  
  26. #define CURUP    72
  27. #define CURDWN    80
  28. #define CURLEFT 75
  29. #define CURRIT  77
  30. #define HOME    71
  31. #define END    79
  32. #define INS    82
  33. #define DEL    83
  34.  
  35. char saveBuffer[4096];
  36. short getkey(void);
  37.  
  38. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  39.            LPSTR lpszCmdline, int cmdshow)
  40.  {
  41.     HWND hwnd;
  42.     WNDCLASS wc;
  43.     RECT r;
  44.     MSG msg;
  45.  
  46.     /* Register Main Window Class */
  47.  
  48.     hInst = hInstance;
  49.  
  50.     if (!hPrevInstance)
  51.      {
  52.         wc.style = 0;
  53.         wc.lpfnWndProc = WndProc;
  54.         wc.cbClsExtra = 0;
  55.         wc.cbWndExtra = 0;
  56.         wc.hInstance = hInstance;
  57.         wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
  58.         wc.hCursor = LoadCursor( 0, IDC_ARROW );
  59.         wc.hbrBackground = COLOR_WINDOW + 1;
  60.         wc.lpszMenuName = "Example5";
  61.         wc.lpszClassName = "Example5";
  62.         RegisterClass( &wc );
  63.      }
  64.  
  65.  
  66.     /* Initialize terminal IO */
  67.     WinDosIO(WD_INIT,hInstance,0);
  68.  
  69.     /* Create Main Window */
  70.     hwnd = CreateWindow(
  71.                 "Example5",
  72.                 "A Very Dumb Screen Editor",
  73.                 (WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME),
  74.                 CW_USEDEFAULT,
  75.                 0,
  76.                 CW_USEDEFAULT,
  77.                 0,
  78.                 0,
  79.                 0,
  80.                 hInstance,
  81.                 NULL
  82.                 );
  83.  
  84.     ShowWindow(hwnd, cmdshow);
  85.  
  86.     /* Create menu window */
  87.     r.top = 0;
  88.     r.left = 0;
  89.     idWindow = CreateWindow("termIO","Edit Window",
  90.               WS_CHILD ,
  91.               r.left,r.top,640,360,
  92.               hwnd,20,hInstance,0);
  93.     ShowWindow(idWindow,SW_SHOW);
  94.     UpdateWindow(idWindow);
  95.  
  96.     textcolor(LIGHTBLUE);
  97.     gotoxy(1,26);
  98.     printf("F1-HVideo F2-LVideo F3-80c F4-40c F5-Save F6-Rest F7-Copy");
  99.     window(1,1,80,25);
  100.     textcolor(WHITE);
  101.     textbackground(BLACK);
  102.     gotoxy(1,1);
  103.     for(;;)
  104.          {
  105.         short k = getkey();
  106.         if (k < 0) break;
  107.         switch (k)
  108.          {
  109.            case CURDWN:
  110.             if (wherey() < 25) gotoxy(wherex(),wherey()+1);
  111.                 break;
  112.            case CURUP:
  113.             if (wherey() > 1) gotoxy(wherex(),wherey()-1);
  114.                 break;
  115.            case CURLEFT:
  116.             if (wherex() > 1) gotoxy(wherex()-1,wherey());
  117.             break;
  118.            case CURRIT:
  119.             if (wherex() < 80) gotoxy(wherex()+1,wherey());
  120.             break;
  121.            case HOME:
  122.             gotoxy(1,1);
  123.                  break;
  124.            case END:
  125.             gotoxy(80,25);
  126.                 break;
  127.            case INS:
  128.             insline();
  129.             break;
  130.            case DEL:
  131.             delline();
  132.             break;
  133.            case F1:
  134.             highvideo();
  135.             break;
  136.            case F2:
  137.             lowvideo();
  138.             break;
  139.            case F3:
  140.             textmode(C80);
  141.             window(1,1,80,25);
  142.             break;
  143.            case F4:
  144.             textmode(C40);
  145.             window(1,1,80,25);
  146.             break;
  147.            case F5:
  148.             saved = 1;
  149.             gettext(1,1,80,25,saveBuffer);
  150.             break;
  151.            case F6:
  152.             if (saved)
  153.                puttext(1,1,80,25,saveBuffer);
  154.             break;
  155.            case F7:
  156.             movetext(5,1,10,2,wherex(),wherey());
  157.             break;
  158.            default:
  159.             if (isText)
  160.               {
  161.                 char ch = k - 256;
  162.                 putchar(ch);
  163.               }
  164.             break;
  165.         }
  166.      }
  167.     closegraph();
  168.     while( GetMessage( &msg, 0, 0, 0 ) != 0 )
  169.          {
  170.         TranslateMessage( &msg );
  171.         DispatchMessage( &msg );
  172.          }
  173.  
  174.     return 0;
  175.  }
  176.  
  177. short getkey(void)
  178.  {
  179.     int k = getch();
  180.     isText = 1;
  181.     if (!k)
  182.      {
  183.        isText = 0;
  184.          return getch();
  185.      }
  186.     if (k > 0)
  187.         return k + 256;
  188.     else    return k;
  189.  }
  190.  
  191. long far pascal WndProc(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
  192.  {
  193.  
  194.     switch( msg )
  195.         {
  196.     case WM_COMMAND:
  197.         break;
  198.     case WM_SETFOCUS:
  199.         WinDosIO(WD_SETFOCUS,0,0);
  200.         break;
  201.     case WM_CLOSE:
  202.             WinDosIO(WD_DESTROY,hwnd,0);
  203.         return 0;
  204.         case WM_DESTROY:
  205.         PostQuitMessage(0);
  206.             return 0;
  207.         }
  208.  
  209.     return DefWindowProc(hwnd,msg,wParam,lParam);
  210. }
  211.  
  212.  
  213.